﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GlxRRSDB.ReportDataSetTableAdapters;
using GlxRRSDB;
using GlxRRSReporter.DailyReporter;
using GlxRRSDB.Data;
using GlxRRSDB.Facades;
using GlxRRSMain.Utils;

namespace GlxRRSMain.UserControls
{
    public partial class MonthlyReportByCinemaControl : UserControl
    {
        private tblCinemaTableAdapter x_tblCinemaTableAdapter = new tblCinemaTableAdapter();
        private List<ReportDataSet.tblCinemaRow> x_ListCinema = null;
        public MonthlyReportByCinemaControl()
        {
            InitializeComponent();
        }
        public List<ReportDataSet.tblCinemaRow> ListCinema
        {
            get
            {
                if (x_ListCinema == null)
                {
                    x_ListCinema = x_tblCinemaTableAdapter.GetData().ToList();
                }
                return x_ListCinema;
            }
            set
            {
                x_ListCinema = value;
            }
        }
        private void MonthlyReportByCinemaControl_Load(object sender, EventArgs e)
        {
            cbCinema.DataSource = ListCinema;
            cbCinema.DisplayMember = "CinemaName";
            cbCinema.ValueMember = "ID";
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            ReportDataSet.tblCinemaRow cinema = (ReportDataSet.tblCinemaRow)cbCinema.SelectedItem;
            int cinemaid = cinema.ID;
            string cinemaName = cinema.CinemaName;
            int year = DateTime.Now.Year;
            //
            Dictionary<int, Dictionary<int, MonthlyReportData>> dictBO = MonthlyReportFacade.getBOMonthlyReport(year, cinemaid);
            Dictionary<int, Dictionary<int, MonthlyReportData>> dictCO = MonthlyReportFacade.getCOMonthlyReport(year, cinemaid);
            Dictionary<int, Dictionary<int, MonthlyReportData>> dictAdmission = MonthlyReportFacade.getAdmissionMonthlyReport(year, cinemaid);

            //
            generateMonthlyReportByCinema(year, cinemaid, cinemaName, dictBO, dictCO, dictAdmission);
        }
        private void generateMonthlyReportByCinema(int year, int cinemaId, string cinemaName,
            Dictionary<int, Dictionary<int, MonthlyReportData>> dictBO,
            Dictionary<int, Dictionary<int, MonthlyReportData>> dictCO,
            Dictionary<int, Dictionary<int, MonthlyReportData>> dictAdmission)
        {
            MonthlyReporter.init(FileHelper.getMonthlyReportByCinemaTemplate(), FileHelper.genMonthlyReportByCinemaTemplateOut());
            MonthlyReporter.generateMonthlyReportByCinema(year, cinemaId, cinemaName, dictBO, dictCO, dictAdmission);
        }
    }
}
